/**
 * Array adapter necessary for creation of list of file detailes 
 */
package org.amse.ys.sndeditor.ui;

import java.io.File;
import java.util.ArrayList;
import org.amse.ys.sndeditor.model.ISoundFileDescription;
import org.amse.ys.sndeditor.model.Localiser;
import org.amse.ys.sndeditor.model.filesearcher.FileSearcher;
import org.amse.ys.sndeditor.ui.R.string;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

class FileListAdapter extends BaseAdapter {
	private ArrayList<ISoundFileDescription> myListOfFiles;
	private Context myContext;

	public FileListAdapter(Context context) {
		myContext = context;
		refreshFileList();
	}

	public int getCount() {
		return myListOfFiles.size();
	}

	public File getFile(int position) {
		return myListOfFiles.get(position).giveFile();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		FileView sv;
		if (convertView == null) {
			sv = new FileView(myContext, myListOfFiles.get(position)
					.extractFileName(), Localiser.getString(string.size)
					+ myListOfFiles.get(position).giveSize());
		} else {
			sv = (FileView) convertView;
			sv.setName(myListOfFiles.get(position).extractFileName());
			sv.setComment(Localiser.getString(string.size)
					+ myListOfFiles.get(position).giveSize());
		}

		return sv;
	}

	public void refreshFileList() {
		myListOfFiles = new ArrayList<ISoundFileDescription>(FileSearcher
				.giveSupportedFiles());
	}

}
